package com.knife.oauth.api.controller.v1;

import com.knife.common.utils.Results;
import com.knife.lov.infra.annotations.KnifeProcessLovValue;
import com.knife.oauth.api.vo.IamMenuTree;
import com.knife.oauth.app.service.IamMenuService;
import com.knife.oauth.domain.entity.IamMenu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜单权限表(IamMenu)表控制层
 *
 * @author tianhao.luo@hand-china.com
 * @since 2025-08-13 14:19:32
 */

@RestController("iamMenuController.v1")
@RequestMapping("/v1/{organizationId}/iam-menus")
public class IamMenuController {

    @Autowired
    private IamMenuService iamMenuService;

    @GetMapping("/tree")
    public ResponseEntity<List<IamMenuTree>> selectTree(@PathVariable Long organizationId) throws IllegalAccessException {
        return Results.success(iamMenuService.selectTree(organizationId));
    }

    @PostMapping
    public ResponseEntity<IamMenu> saveOrUpdateMenu(@PathVariable Long organizationId, @RequestBody IamMenu iamMenu) {
        iamMenu.setTenantId(organizationId);
        return Results.success(iamMenuService.saveOrUpdateMenu(iamMenu));
    }


    @DeleteMapping
    public ResponseEntity<IamMenu> deleteMenu(@PathVariable Long organizationId, @RequestBody IamMenu iamMenu) {
        iamMenu.setTenantId(organizationId);
        return Results.success(iamMenuService.deleteMenu(iamMenu));
    }
}

